//
//  KeyChainManager.swift
//  TopStock
//
//  Created by dyd on 2017/9/1.
//  Copyright © 2017年 dyd. All rights reserved.
//

import UIKit

class KeyChainManager: NSObject {
    
    //密码和账号的保存
    
    func createDefaultKeyChainItemDic()->NSMutableDictionary{
        let keyChainItem = NSMutableDictionary()
        keyChainItem.setObject(kSecClassInternetPassword as NSString, forKey: kSecClass as NSString)
        keyChainItem.setObject("blog.csdn.net/hello_hwc", forKey:  kSecAttrServer as NSString)
//        keyChainItem.setObject(phoneNumTextField.text, forKey: kSecAttrAccount as NSString)
        return keyChainItem
    }
    
    func addKeyChainItem() {
        let keyChainItem = self.createDefaultKeyChainItemDic()
        if SecItemCopyMatching(keyChainItem,nil) == noErr{
            //            self.alertWithMessage("User name already exits")
        }else{
//            keyChainItem.setObject(phoneNumTextField.text!.data(using: String.Encoding.utf8, allowLossyConversion:true)!, forKey: kSecValueData as String as String as NSCopying)
//            var status = SecItemAdd(keyChainItem, nil)
            //            self.alertWithStatus(status)
        }
    }
    
    func updateKeyChainItem() {
        let keyChainItem = self.createDefaultKeyChainItemDic()
        if SecItemCopyMatching(keyChainItem,nil) == noErr{
//            let updateDictionary = NSMutableDictionary()
//            updateDictionary.setObject(phoneNumTextField.text!.data(using: String.Encoding.utf8, allowLossyConversion:true)!, forKey:kSecValueData as String as String as NSCopying)
//            var status = SecItemUpdate(keyChainItem,updateDictionary)
            //            self.alertWithStatus(status)
        }else{
            //            self.alertWithMessage("The keychain doesnot exist")
        }
    }

    

}
